package utility.load_save;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Class to write a save file.
 * @author Zachary
 *
 */
public class SaveFileWriter {
	private static String fileDirectory = "GameSaves\\";
	
	
	/**
	 * Change the file directory.
	 * @param directory
	 */
	public static void changeFileDirectory(String directory){
		fileDirectory = directory;
	}
	
	/**
	 * Write data in the string to file.
	 * @param data
	 */
	public static void writeToFile(String data){
		String[] deliminatedData = data.split("\n");
		String name = deliminatedData[0];
		
		BufferedWriter buffer = null;
		FileWriter writer = null;
		
		try{
			File file = new File(fileDirectory + name);
			writer = new FileWriter(file);
			buffer = new BufferedWriter(writer);
			buffer.write(data);
			
		} catch(IOException ioe){
			ioe.printStackTrace();
		} finally{
			try{
			if(buffer != null)
				buffer.close();
			if(writer != null)
				writer.close();
			} catch(IOException ioe){
				ioe.printStackTrace();
			}
		}
	}
}
